package sz;

import pojo.entity.Person;

import java.lang.reflect.Field;

public class MethodGetAndSet {
    public static void main(String[] args) {
        try {
            Class clz=Class.forName("pojo.entity.Person");
            Person person= (Person) clz.newInstance();
            Field name=clz.getDeclaredField("name");
            name.setAccessible(true);
            //获取name属性
            System.out.println("取值"+name.get(person));
            //设置属性
            name.set(person,"李章涛");
            //输出赋值之后的属性
            System.out.println("赋值"+name.get(person));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
